package bavaria.hightech.testit.pruefungen.ws09;

public class GridPoint implements Comparable<GridPoint>{
	
	public final int row;
	public final int col;
	
	public GridPoint(int row, int col) {
		this.row = row;
		this.col = col;
	}
	
	public String toString(){
		return ")" +row +"," +col +")";
	}

	
	public GridPoint neg(){
		return new GridPoint( row*(-1), col*(-1));
	}
	
	public GridPoint plus(GridPoint delta){
		return new GridPoint(row + delta.row, col + delta.col);
	}
	
	public boolean equals(Object o){
		if(o instanceof GridPoint){
			GridPoint second = (GridPoint)o;
			return (row == second.row && col == second.col);
		}else{
			return false;
		}
	}
	
	@Override
	public int compareTo(GridPoint rc){
		if (row < rc.row ) //first ordering criterion
			return -1;
		else if(row > rc.row)
			return 1;
		else{ //second ordering criterion
			if (col == rc.col)
				return 0; // both points have same location
			return col<rc.col?-1:1;
		}
		
	}
	
	

}
